#============================================================
#	Ground Enemy Attack
#============================================================
# @datetime: 2022-4-22 12:34:36
#============================================================
class_name GroundEnemyAttack
extends GroundEnemyBase


var _jump_timer : Timer = create_timer(3)
var _jumping : bool = false
var _jump_height : float = 0.0


#============================================================
#   内置
#============================================================
func _ready():
	_jump_height = WrapperHelper.get_property(owner).get_property("jump_height")


#============================================================
#   状态
#============================================================
#(override)
func state_process(delta):
	if get_host().is_on_floor():
		_jumping = false
	
	if has_player():
		var dist = get_player().global_position.x - get_host().global_position.x
		if (abs(dist) > 8):
			input_move_direction(sign(dist))
			
			# 一秒内有 30% 概率在可以攻击时进行攻击
			if randf() <= 0.3 * delta:
				if _jump_timer.time_left == 0 and MathUtil.between(abs(dist), 20, 50):
					_jump_timer.start()
					_jumping = true
					input_jump(rand_range(_jump_height * 0.6, _jump_height))
		
	elif _jumping:
		input_forward_move()
		
	else:
		switch_to(GroundEnemyStateBlackboard.States.LOOK_AROUND)


